<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body style="padding: 0px">
<div class="layui-card" style="padding: 0px;margin: 0px">
    <div class="layui-card-body" style="padding-top: 10px;">
        <form class="layui-form layui-form-pane" action="" lay-filter="user-add-form">

            <div class="layui-collapse">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">基础信息(新用户密码默认12456)</h2>
                    <div class="layui-colla-content layui-show">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">账号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="userCode" disabled="disabled" lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">姓名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="userName" lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">部门</label>
                                <div class="layui-input-inline">
                                    <select  name="deptId" lay-verify="required" xm-select="dept" xm-select-radio="" xm-select-search="" xm-select-height="36px">
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">区域</label>
                                <div class="layui-input-inline">
                                    <select  name="orgId" lay-verify="required" xm-select="org" xm-select-radio=""xm-select-search="" xm-select-height="36px"	>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">电话</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="phone" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">状态</label>
                                <div class="layui-input-inline">
                                    <select  name="isActive" lay-verify="required" xm-select="isActive" xm-select-radio="" xm-select-height="36px" disabled="disabled"	>
                                        <option value="1">在职</option>
                                        <option value="0">离职</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">扩展信息</h2>
                    <div class="layui-colla-content">

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">生日</label>
                                <div class="layui-input-inline">
                                    <input type="text"  name="birth"  id="birth"   autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">性别</label>
                                <div class="layui-input-inline">
                                    <select name="gender"  xm-select="gender" xm-select-radio="">
                                        <option value="1">男</option>
                                        <option value="0">女</option>
                                        <option value="2">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">学历</label>
                                <div class="layui-input-inline">
                                    <select  name="education" lay-verify="" xm-select="education-s" xm-select-radio=""xm-select-search="" xm-select-height="36px"	>
                                    </select>
                                </div>
                            </div>


                            <div class="layui-inline">
                                <label class="layui-form-label">岗位</label>
                                <div class="layui-input-inline">
                                    <select  name="position" lay-verify="" xm-select="position-s" xm-select-radio=""xm-select-search="" xm-select-height="36px"	>
                                    </select>
                                </div>
                            </div>
                        </div>


                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">薪资</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="salary" disabled="disabled" lay-verify="number" autocomplete="off" class="layui-input" value="">
                                </div>
                            </div>


                            <div class="layui-inline">
                                <label class="layui-form-label">QQ</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="qq" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">微信</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="weiXin" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="email" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">

                            <label class="layui-form-label">地址</label>
                            <div class="layui-input-block" style="width: 70%">
                                <textarea name="address" placeholder="请输入内容" class="layui-textarea"></textarea>
                            </div>

                        </div>

                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" lay-submit="" lay-filter="user-add-form-bt">保存</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
</body>


<script type="text/html" id="user-info-changePassword">
    <div class="layui-card" style="padding: 0px;margin: 0px">
        <div class="layui-card-body" style="padding-top: 10px;">
            <form class="layui-form layui-form-pane" action="" lay-filter="user-changePassword-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">旧密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="oldPassWord" lay-verify="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="passWord" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">再次输入</label>
                        <div class="layui-input-inline">
                            <input type="password" name="repassWord" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="user-changePassword-bt">保存</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</script>
</html>

<script type="text/javascript">
    var layindex,layevent;
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'form','formSelects','laydate',"element"], function() {
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var router = layui.router();
        var formSelects = layui.formSelects;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var element = layui.element
        var layIndex ;

        if(urlParam.indexOf("id")!=-1 || urlParam.indexOf("userCode") != -1){
            var param = {token: token}
            var editForm = $("form[lay-filter='user-add-form']")
            console.log(basePath+"/user/getOne"+urlParam)
            $.getJSON(basePath+"/user/getOne"+urlParam,param,function(res){
                if(res.code !=0){
                    layer.msg(res.msg)
                }else{
                    var data = res.data;
                    editForm.find("input[name=userName]").val(data.userName)
                    editForm.find("input[name=userCode]").val(data.userNo).attr("readonly","readonly")
                    editForm.find("input[name=email]").val(data.email)

                    editForm.find("input[name=phone]").val(data.phone)
                    editForm.find("input[name=qq]").val(data.qq)
                    editForm.find("input[name=weiXin]").val(data.weiXin);
                    editForm.find("input[name=salary]").val(data.salary).attr("readonly","readonly");
                    editForm.find("textarea[name=address]").val(data.address);
                    formSelects.value('gender', [data.gender]);
                    formSelects.value('isActive', [data.isActive]);

                    //layer.close(index);
                    //return true;
                    laydate.render({
                        elem:"#birth",
                        value:data.birth});

//                    layui.formSelects.config('org', {
//                        searchUrl: basePath+'/user/selectOrgTreeData?token='+token,
//                        success: function(id, url, searchVal, result){
//                            formSelects.value('org', [data.orgId]);
//                        }
//                    });
//
//                    layui.formSelects.config('dept', {
//                        searchUrl: basePath+'/user/selectDeptTreeData?token='+token,
//                        success: function(id, url, searchVal, result){
//                            formSelects.value('dept', [data.deptId]);
//                        }
//                    });

                    formSelects.data('org', 'server', {
                        url: basePath+'/user/selectOrgTreeData',
                        data:{token:token},
                        //linkage: true,
                        linkageWidth: 180,   //代表每一级别的宽度, 默认是100
                        success: function(id, url, searchVal, result){
                            formSelects.value('org', [data.orgId]);
                        }
                    });

                    formSelects.data('dept', 'server', {
                        url: basePath+'/user/selectDeptTreeData',
                        data:{token:token},
                        //linkage: true,
                        linkageWidth: 180,   //代表每一级别的宽度, 默认是100
                        success: function(id, url, searchVal, result){
                            formSelects.value('dept', [data.deptId]);
                        }
                    });

                    formSelects.data('education-s', 'server', {
                        url: basePath+'/sysParams/getParamSelect',
                        data:{token:token,paramsType:"education".toUpperCase()},
                        //linkage: true,
                        linkageWidth: 180 ,  //代表每一级别的宽度, 默认是100
                        success: function(id, url, searchVal, result){
                            formSelects.value('education-s', [data.education]);
                        }
                    });

                    formSelects.data('position-s', 'server', {
                        url: basePath+'/sysParams/getParamSelect',
                        data:{token:token,paramsType:"position".toUpperCase()},
                        //linkage: true,
                        linkageWidth: 180 ,  //代表每一级别的宽度, 默认是100
                        success: function(id, url, searchVal, result){
                            formSelects.value('position-s', [data.position]);
                        }
                    });

                }
            } )
            $(".layui-footer").prepend('<button class="layui-btn layui-btn-warm"  id="user-reset-password">修改密码</button>')
        }

        form.on("submit(user-add-form-bt)",function(data){
            var param = data.field;
            param.token = token;
            var url =  url =  basePath+"/user/edit"

            $.post(url,param,function(res){
                if(res.code !=0){
                    layer.msg(res.msg)
                }else{
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
                return false;
            } ,'json')
            return false ;
        })

        $("#user-reset-password").click(function(data){
            layIndex = layer.open({
                type:1,
                title:"<i class='layui-icon layui-icon-note'></i> 修改密码",
                content:$("#user-info-changePassword").html()
            })
            return false ;
        })


        form.on("submit(user-changePassword-bt)",function(obj){
            var param = obj.field
            param.token = token;
            var url = basePath+"/user/changePassword"+urlParam;
            console.log(param)
            $.post(url,param,function(res){
                layer.msg(res.msg)
                if(res.code == 0 ){
                    layer.close(layIndex);
                }
                return false;
            } ,'json')
            return false
        })

    })
</script>

